<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>服务管理系统</title>
    <link rel="stylesheet" href="css/style.css">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Arial', sans-serif;
        }
        body {
            background-color: #f5f5f5;
            color: #333;
            padding: 0; 
            padding-bottom: 70px; /* 为底部任务栏留出空间 */
        }
        .container {
            max-width: 450px; /* 设置整体宽度为450px */
            margin: 0 auto; /* 居中显示 */
            background-color: white;
            border-radius: 10px 10px 0 0; /* 顶部圆角 */
            box-shadow: 0 2px 10px rgba(0,0,0,0.1); /* 恢复阴影 */
            padding: 20px;
            min-height: 100vh; /* 确保内容填满屏幕高度 */
        }
        h1 {
            text-align: center;
            margin-bottom: 30px;
            color: #2c3e50;
            font-size: 22px;
        }
        .service-status {
            margin-bottom: 30px;
            padding: 20px;
            border-radius: 8px;
            background-color: #f8f9fa;
            border-left: 4px solid #3498db;
            width: 430px; /* 设置宽度为430px */
            margin-left: auto; /* 左右margin设为auto实现居中 */
            margin-right: auto;
        }
        .status-title {
            font-size: 18px;
            font-weight: bold;
            margin-bottom: 15px;
            color: #2c3e50;
        }
        /* 进度条样式 */
        .progress-container {
            margin: 20px 0;
        }
        .progress-bar {
            width: 100%;
            height: 10px;
            background-color: #e0e0e0;
            border-radius: 5px;
            overflow: hidden;
            margin-bottom: 10px;
        }
        .progress-fill {
            height: 100%;
            background-color: #3498db;
            width: 66%; /* 当前完成度 */
            transition: width 0.5s ease;
        }
        .progress-details {
            display: flex;
            justify-content: space-between;
            font-size: 14px;
            color: #7f8c8d;
        }
        .worker-info {
            margin-top: 15px;
            padding: 10px;
            background-color: #eef6fc;
            border-radius: 5px;
        }
        .worker-name {
            font-weight: bold;
            color: #2c3e50;
            margin-bottom: 5px;
        }
        .order-status {
            display: flex;
            align-items: center;
            font-size: 14px;
        }
        .status-indicator {
            width: 10px;
            height: 10px;
            border-radius: 50%;
            margin-right: 5px;
        }
        .status-indicator.accepted {
            background-color: #2ecc71;
        }
        .refresh-btn {
            display: block;
            margin: 20px auto;
            padding: 10px 20px;
            background-color: #3498db;
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            transition: background-color 0.3s ease;
            width: 400px; /* 设置按钮宽度为400px */
        }
        .refresh-btn:hover {
            background-color: #2980b9;
        }
        .service-history {
            margin-top: 40px;
            width: 430px; /* 设置宽度为430px */
            margin-left: auto; /* 左右margin设为auto实现居中 */
            margin-right: auto;
        }
        .history-title {
            font-size: 18px;
            font-weight: bold;
            margin-bottom: 15px;
            color: #2c3e50;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        .history-filters {
            display: flex;
            gap: 10px;
            margin-bottom: 15px;
        }
        .filter-btn {
            padding: 8px 15px;
            background-color: #e0e0e0;
            color: #7f8c8d;
            border: none;
            border-radius: 20px;
            cursor: pointer;
            transition: all 0.3s ease;
            font-size: 14px;
        }
        .filter-btn.active {
            background-color: #3498db;
            color: white;
        }
        .history-list {
            max-height: 400px;
            overflow-y: auto;
        }
        .history-item {
            padding: 15px;
            border-bottom: 1px solid #e0e0e0;
            transition: background-color 0.2s ease;
        }
        .history-item:hover {
            background-color: #f8f9fa;
        }
        .history-item-header {
            display: flex;
            justify-content: space-between;
            margin-bottom: 10px;
        }
        .history-date {
            font-size: 14px;
            color: #7f8c8d;
        }
        .history-status {
            font-size: 14px;
            padding: 3px 8px;
            border-radius: 12px;
            background-color: #e0e0e0;
            color: #7f8c8d;
        }
        .history-status.completed {
            background-color: #2ecc71;
            color: white;
        }
        .history-status.pending {
            background-color: #f39c12;
            color: white;
        }
        .history-status.cancelled {
            background-color: #e74c3c;
            color: white;
        }
        .history-type {
            font-weight: bold;
            margin-bottom: 5px;
        }
        .modal {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0,0,0,0.5);
            z-index: 1000;
            justify-content: center;
            align-items: center;
        }
        .modal-content {
            background-color: white;
            border-radius: 10px;
            padding: 30px;
            width: 90%;
            max-width: 400px;
            text-align: center;
        }
        .modal-title {
            font-size: 18px;
            font-weight: bold;
            margin-bottom: 20px;
        }
        .modal-buttons {
            display: flex;
            justify-content: center;
            gap: 20px;
            margin-top: 30px;
        }
        .modal-btn {
            padding: 10px 25px;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            font-weight: bold;
            transition: background-color 0.3s ease;
        }
        .btn-yes {
            background-color: #2ecc71;
            color: white;
        }
        .btn-yes:hover {
            background-color: #27ae60;
        }
        .btn-no {
            background-color: #e74c3c;
            color: white;
        }
        .btn-no:hover {
            background-color: #c0392b;
        }
        /* 刷新状态弹窗样式 */
        .refresh-modal {
            display: none;
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            width: 90%;
            max-width: 350px;
            background-color: white;
            border-radius: 10px;
            box-shadow: 0 5px 15px rgba(0,0,0,0.3);
            z-index: 1000;
            overflow: hidden;
        }
        .refresh-modal-content {
            padding: 30px 20px;
            text-align: center;
            border-bottom: 1px solid #e0e0e0;
        }
        .refresh-modal-title {
            font-size: 18px;
            font-weight: bold;
            margin-bottom: 15px;
            color: #2c3e50;
        }
        .refresh-modal-message {
            font-size: 16px;
            color: #7f8c8d;
        }
        .refresh-modal-buttons {
            display: flex;
        }
        .refresh-modal-btn {
            flex: 1;
            padding: 15px;
            border: none;
            font-size: 16px;
            font-weight: bold;
            cursor: pointer;
        }
        .btn-back {
            background-color: #f5f5f5;
            color: #7f8c8d;
        }
        .btn-refresh-again {
            background-color: #3498db;
            color: white;
        }
        .pull-to-refresh {
            text-align: center;
            padding: 10px;
            color: #7f8c8d;
            font-size: 14px;
        }
        /* 底部任务栏样式 */
        .bottom-nav {
            position: fixed;
            bottom: 0;
            left: 0;
            right: 0;
            max-width: 450px; /* 与页面宽度一致 */
            margin: 0 auto; /* 居中显示 */
            background-color: white;
            box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
            display: flex;
            justify-content: space-around;
            padding: 10px 0;
            z-index: 999;
            border-radius: 10px 10px 0 0;
        }
        .nav-item {
            display: flex;
            flex-direction: column;
            align-items: center;
            color: #7f8c8d;
            text-decoration: none;
            font-size: 12px;
        }
        .nav-item.active {
            color: #3498db;
        }
        .nav-icon {
            width: 24px;
            height: 24px;
            object-fit: contain;
            margin-bottom: 5px;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>我的服务</h1>

        <!-- 服务状态跟踪 -->
        <div class="service-status">
            <div class="status-title">当前服务进度</div>
            
            <!-- 进度条 -->
            <div class="progress-container">
                <div class="progress-bar">
                    <div class="progress-fill" id="progressFill"></div>
                </div>
                <div class="progress-details">
                    <span>取件</span>
                    <span id="progressPercentage">66%</span>
                    <span id="deliveryStatus">配送中</span>
                </div>
            </div>
            
            <!-- 工作人员信息 -->
            <div class="worker-info">
                <div class="worker-name">师傅姓名: 张三</div>
                <div class="order-status">
                    <span class="status-indicator accepted"></span>
                    <span>已接单，正在处理中</span>
                </div>
            </div>
            
            <button class="refresh-btn" onclick="refreshStatus()">刷新状态</button>
            <button class="refresh-btn" onclick="contactService()">联系客服</button>
        </div>

        <!-- 服务历史记录 -->
        <div class="service-history">
            <div class="history-title">
                历史服务记录
                <span class="pull-to-refresh" onclick="refreshHistory()">下拉刷新</span>
            </div>
            <div class="history-filters">
                <button class="filter-btn active" onclick="filterHistory('all')">全部</button>
                <button class="filter-btn" onclick="filterHistory('completed')">已完成</button>
                <button class="filter-btn" onclick="filterHistory('cancelled')">已取消</button>
            </div>
            <div class="history-list" id="historyList">
                <div class="history-item">
                    <div class="history-item-header">
                        <span class="history-date">2025-07-28 14:30</span>
                        <span class="history-status completed">已完成</span>
                    </div>
                    <div class="history-type">快递代收服务</div>
                    <div class="history-details">物品：文件，数量：1</div>
                </div>
                <div class="history-item">
                    <div class="history-item-header">
                        <span class="history-date">2025-07-25 09:15</span>
                        <span class="history-status completed">已完成</span>
                    </div>
                    <div class="history-type">包裹配送服务</div>
                    <div class="history-details">物品：电子产品，数量：1</div>
                </div>
                <div class="history-item">
                    <div class="history-item-header">
                        <span class="history-date">2025-07-20 16:45</span>
                        <span class="history-status cancelled">已取消</span>
                    </div>
                    <div class="history-type">生鲜配送服务</div>
                    <div class="history-details">物品：水果，数量：1箱</div>
                </div>
                <div class="history-item">
                    <div class="history-item-header">
                        <span class="history-date">2025-07-15 11:20</span>
                        <span class="history-status cancelled">已取消</span>
                    </div>
                    <div class="history-type">家具配送服务</div>
                    <div class="history-details">物品：椅子，数量：2把</div>
                </div>
                <!-- 移除进行中的项目 -->
            </div>
        </div>
    </div>

    <!-- 服务确认弹窗 -->
    <div class="modal" id="confirmationModal">
        <div class="modal-content">
            <div class="modal-title">是否收到服务？</div>
            <p>您的快递配送服务已完成，请确认是否收到物品。</p>
            <div class="modal-buttons">
                <button class="modal-btn btn-yes" onclick="confirmService(true)">是</button>
                <button class="modal-btn btn-no" onclick="confirmService(false)">否</button>
            </div>
        </div>
    </div>

    <!-- 刷新状态弹窗 -->
    <div class="refresh-modal" id="refreshModal">
        <div class="refresh-modal-content">
            <div class="refresh-modal-title">状态已更新</div>
            <div class="refresh-modal-message">当前服务进度已更新至最新状态</div>
        </div>
        <div class="refresh-modal-buttons">
            <button class="refresh-modal-btn btn-back" onclick="closeRefreshModal()">返回</button>
            <button class="refresh-modal-btn btn-refresh-again" onclick="refreshStatusAgain()">继续刷新</button>
        </div>
    </div>

    <!-- 底部任务栏 -->
    <div class="bottom-nav">
        <a href="#" class="nav-item">
            <img src="img/1.jpg" class="nav-icon" alt="首页">
            <div class="nav-text">首页</div>
        </a>
        <a href="#" class="nav-item">
            <img src="img/2.jpg" class="nav-icon" alt="预约服务">
            <div class="nav-text">预约服务</div>
        </a>
        <a href="#" class="nav-item">
            <img src="img/3.jpg" class="nav-icon" alt="社区中心">
            <div class="nav-text">社区中心</div>
        </a>
        <a href="#" class="nav-item active">
            <img src="img/4.jpg" class="nav-icon" alt="服务管理">
            <div class="nav-text">服务管理</div>
        </a>
        <a href="#" class="nav-item">
            <img src="img/5.jpg" class="nav-icon" alt="个人中心">
            <div class="nav-text">个人中心</div>
        </a>
    </div>

    <script>
        // 模拟状态更新
        function refreshStatus() {
            // 这里应该是异步请求后端获取最新状态
            // 这里用setTimeout模拟网络请求
            setTimeout(() => {
                // 随机更新进度（仅作演示）
                const progressFill = document.getElementById('progressFill');
                const progressPercentage = document.getElementById('progressPercentage');
                const currentProgress = parseInt(progressFill.style.width || '66');
                const newProgress = Math.min(currentProgress + Math.floor(Math.random() * 15), 100);
                
                progressFill.style.width = newProgress + '%';
                progressPercentage.textContent = newProgress + '%';
                
                // 如果进度达到100%，显示确认弹窗
                if (newProgress === 100) {
                    document.getElementById('confirmationModal').style.display = 'flex';
                } else {
                    // 显示自定义刷新状态弹窗
                    document.getElementById('refreshModal').style.display = 'block';
                }
                
                // 移除原来的alert
                // alert('状态已更新');
            }, 1000);
        }

        // 关闭刷新状态弹窗
        function closeRefreshModal() {
            document.getElementById('refreshModal').style.display = 'none';
        }

        // 继续刷新
        function refreshStatusAgain() {
            closeRefreshModal();
            refreshStatus();
        }

        // 确认服务
        function confirmService(isReceived) {
            document.getElementById('confirmationModal').style.display = 'none';
            
            if (isReceived) {
                // 标记服务完成
                // 移除alert弹窗
                // 更新进度条下面的状态文本为"已完成"
                document.getElementById('deliveryStatus').textContent = '已完成';
                // 这里应该调用API通知后端服务已完成
            } else {
                // 反馈问题
                alert('我们已收到您的反馈，门店将尽快跟进处理。');
                // 这里应该调用API通知后端有问题
            }
        }

        // 刷新历史记录
        function refreshHistory() {
            // 这里应该是异步请求后端获取最新历史记录
            // 这里用setTimeout模拟网络请求
            setTimeout(() => {
                const historyList = document.getElementById('historyList');
                // 模拟添加一条新记录
                const newItem = document.createElement('div');
                newItem.className = 'history-item';
                newItem.innerHTML = `
                    <div class="history-item-header">
                        <span class="history-date">${new Date().toLocaleString()}</span>
                        <span class="history-status pending">处理中</span>
                    </div>
                    <div class="history-type">紧急文件配送</div>
                    <div class="history-details">物品：合同，数量：1</div>
                `;
                historyList.insertBefore(newItem, historyList.firstChild);
                
                alert('历史记录已更新');
            }, 1000);
        }

        // 页面加载完成后模拟5秒后状态更新
        window.onload = function() {
            setTimeout(() => {
                // 这里可以模拟后端推送状态更新
                console.log('模拟状态更新推送');
            }, 5000);
        };

        // 联系客服函数
        function contactService() {
            // 跳转到客服界面
            window.location.href = 'customer-service.html';
        }

        // 筛选历史记录
        function filterHistory(type) {
            // 移除所有按钮的active类
            document.querySelectorAll('.filter-btn').forEach(btn => {
                btn.classList.remove('active');
            });
            // 为当前按钮添加active类
            event.currentTarget.classList.add('active');

            // 获取所有历史记录项
            const historyItems = document.querySelectorAll('.history-item');

            // 根据类型筛选
            historyItems.forEach(item => {
                const status = item.querySelector('.history-status').classList;
                if (type === 'all') {
                    // 显示所有项目（已完成和已取消）
                    item.style.display = 'block';
                } else if (type === 'completed') {
                    // 只显示已完成项目
                    item.style.display = status.contains('completed') ? 'block' : 'none';
                } else if (type === 'cancelled') {
                    // 只显示已取消项目
                    item.style.display = status.contains('cancelled') ? 'block' : 'none';
                }
            });
        }
    </script>
</body>
</html>
